﻿using KTVProject.handle;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KTVProject.frm
{
    public partial class Login : Form
    {
        string tiShi = "提示";
        DBhandle db = new DBhandle();

        public Login()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)  //退出按钮
        {   
            Application.Exit();
        }

        private void btnSign_Click(object sender, EventArgs e)  //登陆按钮
        {
            if (CheckInput())
            {
                FindLogin();
            }
        }

        private void Login_Load(object sender, EventArgs e)
        {

        }

        private bool CheckInput()   //非空验证
        {
            if (txtUser.Text.Trim().Equals(string.Empty) || txtPwd.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("用户名或密码有空值",tiShi,MessageBoxButtons.OK,MessageBoxIcon.Hand);

                return false;
            }
            else
            {
                return true;
            }
        }

        private void FindLogin()    //验证登陆功能
        {
            string userName = txtUser.Text;
            string userPwd = txtPwd.Text;

            int count = (int)db.ExecuteScalar(userName, userPwd);
            if (count == 1)
            {
                KTVManagement kTVManagement = new KTVManagement();
                kTVManagement.Show();

                this.Hide();
            }
            else
            {
                MessageBox.Show("你输入的用户名或密码不正确",tiShi,MessageBoxButtons.OK,MessageBoxIcon.Hand);
            }

            DBhandle.connection.Close();
        }
    }
}
